/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package acceso.util;

//import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.Timer;
import java.util.TimerTask;
//import javax.xml.parsers.DocumentBuilderFactory;
//import org.w3c.dom.Document;
/*import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;*/
import org.xml.sax.SAXException;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterFactory;
import twitter4j.auth.AccessToken;

/**
 *
 * @author romulogalindo
 */
public class Testtwitter {
    Twitter twitter;
    int cont = 0 ; 
    public Testtwitter(){
        /*Timer time = new Timer();
        
        TimerTask task = new TimerTask
                () {

            @Override
            public void run() {
                System.out.println(">"+cont + " " + ((cont%2==0)?"Romulo":" Jurado"));
                cont ++ ;
            }
        };
        
        TimerTask task2 = new TimerTask
                () {

            @Override
            public void run() {
                System.out.println("("+ ((cont-1)*2 - 1) +")------------ Me cago en la puta");
            }
        };
        
        time.scheduleAtFixedRate(task, 0, 1000);
        time.scheduleAtFixedRate(task2, 0, 2000);*/
        
        try{
            
            String menus = "<ul id=\"ja-cssmenu\" class=\"clearfix\"><li class=\"active\"><a href=\"../login2/fwd_servicio2.jsp?co_servic=PUSUMPDU&path=Gestión / Reporte Diario;\" class=\"menu-item0 active first-item\" id=\"menu1\" title=\"Inicio\"><span class=\"menu-title\">Inicio</span></a></li></ul>" ;
            
            menus = menus.replaceAll("&", "&amp;");
            System.out.println("menus:"+menus);
            org.w3c.dom.Document doc =  javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new java.io.ByteArrayInputStream(menus.getBytes()));
            System.out.println("doc:"+doc);
            System.out.println("doc.value:"+doc.getNodeValue());
            System.out.println("doc:CHILD0.CHIL0value:"+doc.getChildNodes().item(0).getChildNodes().item(1).getChildNodes().item(0));

            String link= doc.getChildNodes().item(0).getChildNodes().item(1).getChildNodes().item(0).getAttributes().getNamedItem("href").getNodeValue();
            System.out.println("link:"+link);
            //session.setAttribute("inicio",link);
       }catch(Exception ep){
            System.out.println("1>"+ep.getMessage()+"::"+ep.getClass());
       }
    //.getDocumentElement();


    }
    
    
    public Testtwitter(InputStream input)throws Exception {
        Properties bulldozer_properties_twitter = new Properties();
        bulldozer_properties_twitter.load(input);

        twitter = new TwitterFactory().getInstance();

        twitter.setOAuthConsumer(bulldozer_properties_twitter.getProperty("consumerKey"), bulldozer_properties_twitter.getProperty("consumerSecret"));

        AccessToken accessToken = new AccessToken(bulldozer_properties_twitter.getProperty("twitterToken"), bulldozer_properties_twitter.getProperty("twitterTokenSecret"));

        twitter.setOAuthAccessToken(accessToken);
    }
    
    public String twitear(String mensaje){
        String retorno = "";
        if(mensaje != null){
            try{
                //System.out.println(""+twitter.getId());
                Status status = twitter.updateStatus(mensaje);
                retorno = "OK";
            }catch(Exception ep){
                retorno = ep.getMessage();
            }
        }
        return retorno;
    }
    
    public static void main(String[] args){
        new Testtwitter();
        //Service.cargar();
        //Service.iniciar();
        //Testtwitter t =new Testtwitter();
        //System.out.println(">>"+t.twitear("Test 2 #twitter @dannymarce10"));
        
    }

    
}
